-- ==== BEGIN LICENSE BLOCK ====
-- storyboard-addon - Copyright (C) Arnaud Charnoz, 2006-2010.
-- Distributed under the terms of the GNU Lesser General Public License (LGPL) as
-- published by the Free Software Foundation.
-- ===== END LICENSE BLOCK ====

-- variable
STORYBOARD_REF_POSX = 0
STORYBOARD_REF_POSY = 0
STORYBOARD_REF_HAVELOCATIONHELP = false

-- [ Petite fonction qui affiche les donn�es sur votre position ] -- 
function storyboard_boussole_printPosition() 
   
   local r,g,b = 1,1,0;
   SetMapZoom(GetCurrentMapContinent(),nil);
   SetMapZoom(GetCurrentMapContinent(),nil);
   local continentNames = { GetMapContinents() };
   local continent = continentNames[GetCurrentMapContinent()];
   local px, py = GetPlayerMapPosition("player");
   
   local newpx = px*10000;
   local newpy = py*10000;
   newpx = format("%d", newpx);
   newpy = format("%d", newpy);
   
   newpx = newpx / 100;
   newpy = newpy / 100;
   
   mes = STORYBOARD_MES_LOCATION_001 .. newpx .. " - " .. newpy .. " ]";
   DEFAULT_CHAT_FRAME:AddMessage(mes,1,0,0);
   --storyboard_sendAlertMessage(mes,1);
   
   
   if(STORYBOARD_REF_HAVELOCATIONHELP) then
      local resteX = STORYBOARD_REF_POSX - newpx
      local resteY = STORYBOARD_REF_POSY - newpy
      mes = STORYBOARD_MES_LOCATION_002 .. STORYBOARD_REF_POSX .. " - " .. STORYBOARD_REF_POSY .. " ]";
      DEFAULT_CHAT_FRAME:AddMessage(mes,1,0,0);
      if( resteX < 0 and resteY < 0 ) then
     resteX = format("%d", -resteX*100);
     resteY = format("%d", -resteY*100);
     mes = STORYBOARD_MES_LOCATION_003.. resteX ..STORYBOARD_MES_LOCATION_004.. resteY ..STORYBOARD_MES_LOCATION_006;
     DEFAULT_CHAT_FRAME:AddMessage(mes,r,g,b);
      elseif( resteX >= 0 and resteY < 0 ) then
     resteX = format("%d", resteX*100);
     resteY = format("%d", -resteY*100);
     mes = STORYBOARD_MES_LOCATION_003.. resteX ..STORYBOARD_MES_LOCATION_005.. resteY ..STORYBOARD_MES_LOCATION_006;
     DEFAULT_CHAT_FRAME:AddMessage(mes,r,g,b);
      elseif( resteX < 0 and resteY >= 0 ) then
     resteX = format("%d", -resteX*100);
     resteY = format("%d", resteY*100);
     mes = STORYBOARD_MES_LOCATION_003.. resteX ..STORYBOARD_MES_LOCATION_004.. resteY ..STORYBOARD_MES_LOCATION_007;
     DEFAULT_CHAT_FRAME:AddMessage(mes,r,g,b);
      elseif( resteX >= 0 and resteY >= 0 ) then
     resteX = format("%d", resteX*100);
     resteY = format("%d", resteY*100);
     mes = STORYBOARD_MES_LOCATION_003.. resteX ..STORYBOARD_MES_LOCATION_005.. resteY ..STORYBOARD_MES_LOCATION_007;
     DEFAULT_CHAT_FRAME:AddMessage(mes,r,g,b);
      end
   end

end


-- [ Detect if the payer is on a location  ] --
function storyboard_location_playerIsOnLocation(idContinent,coordX,coordY,distanceZone)
 return  storyboard_location_playerIsOnContinent(idContinent) and storyboard_location_playerIsCloseToPoint(coordX,coordY,distanceZone)
end


-- [ Detect if the payer is on the good continent ] --
function storyboard_location_playerIsOnContinent(idContinent)
 local continent = GetCurrentMapContinent();
 return continent == idContinent
end


-- [ Detect if the payer is close to point ] --
function storyboard_location_playerIsCloseToPoint(coordX,coordY,distanceZone)
  SetMapZoom(GetCurrentMapContinent(),nil);
  SetMapZoom(GetCurrentMapContinent(),nil);
  local px, py = GetPlayerMapPosition("player");

  local newpx = px*10000;
  local newpy = py*10000;
  newpx = format("%d", newpx);
  newpy = format("%d", newpy);

  newpx = newpx / 100;
  newpy = newpy / 100;

  local d1 = ( newpx - coordX ) * ( newpx - coordX ) + ( newpy - coordY ) * ( newpy - coordY )
  local d2 = distanceZone * distanceZone

  return d1 <= d2
end
